package cn.itcast.order.controller;

import cn.itcast.entity.Order;
import cn.itcast.entity.Product;
import cn.itcast.entity.User;
import cn.itcast.order.fegin.ProductFeginClient;
import cn.itcast.order.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
@DefaultProperties(defaultFallback = "orderFallBack")
public class OrderController {

	@Autowired
	private RestTemplate restTemplate;

	//下订单
	@GetMapping("/product/{id}")
	@HystrixCommand
	public Product findProduct(@PathVariable  Long id) {
		return restTemplate.getForObject("http://shop-service-product/product/1", Product.class);
	}


	//降级方法
	public Product orderFallBack(Long id) {
		Product product = new Product();
		product.setId(-1l);
		product.setProductName("熔断:触发降级方法");
		return product;
	}

}
